package com.lcj.eduCms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcj.commonutils.R;
import com.lcj.eduCms.entity.CrmBanner;
import com.lcj.eduCms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/eduCms/admin/banner")
@CrossOrigin
public class CrmBannerController {

    @Autowired
    private CrmBannerService crmBannerService;

    @GetMapping("/{page}/{limit}")
    public R index(@PathVariable Long page, @PathVariable Long limit){
        Page<CrmBanner> bannerPage =new Page<>(page,limit);
        crmBannerService.page(bannerPage,null);
        return R.ok().data("row",bannerPage.getRecords()).data("total",bannerPage.getTotal());
    }

    @GetMapping("get/{id}")
    public R get(@PathVariable String id){
        CrmBanner crmBanner =crmBannerService.getById(id);
        return R.ok().data("banner",crmBanner);
    }

    @PostMapping("save")
    public R save(@RequestBody CrmBanner banner){
        crmBannerService.save(banner);
        return R.ok();
    }

    @PutMapping("update")
    public R updateById(@RequestBody CrmBanner banner){
        crmBannerService.updateById(banner);
        return R.ok();
    }

    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable String id){
        crmBannerService.removeById(id);
        return R.ok();
    }
}

